|
Asynchronous Semaphore is a structure that is used in asynchronous programming models. Its goal is to lock an action, allowing the action to run only after a group of other, asynchronous actions have been executed. The asynchronous semaphore is a specific use of the abstract structure semaphore in the world of asynchronous programming. The semaphore concept was invented by Dutch computer scientist Edsger Dijkstra. == Structure of an asynchronous semaphore == Upon creation, an asynchronous semaphore receives a function as an argument: this argument is usually called the "fire-function". The fire-function will be executed after all the asynchronous actions are completed. The asynchronous semaphore also has a lock variable: a counter which holds the number of asynchronous actions in the queue to be completed. When this counter is zero, all asynchronous actions have been completed and fire function can be called. The asynchronous semaphore has two additional functions: The v() function: When this function is called, the internal semaphore lock variable is increased. This increase represents the fact that one of the asynchronous actions has been called and added to the queue of asynchronous actions waiting to complete. The p() function: When an asynchronous action completes, the p() function is called. The p() function decreases the internal lock variable, representing the fact that an asynchronous action has completed and been removed from the queue. The p() function is called from within the completed asynchronous action's callback function. The p() function also checks if the lock variable, which counts the number of queued asynchronous actions, is zero. If it is, all actions have been completed and the fire function can be called. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Asynchronous semaphore」の詳細全文を読む スポンサード リンク
|